home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9002 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  62 lines

  1. Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
  2. Path: cs.man.ac.uk!clerew!chl
  3. From: chl@clw.cs.man.ac.uk (Charles Lindsey)
  4. Subject: Re: GOTO controversy
  5. Message-ID: <DnwCxp.84C@clw.cs.man.ac.uk>
  6. References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net>
  7. Date: Thu, 7 Mar 1996 12:20:13 GMT
  8.  
  9. In <4hl8mt$4po@newshost.cyberramp.net> sinan@cyberramp.net (John Noland) writes:
  10.  
  11. >>Robert C Shields (rcshlds@mailserv.mta.ca) wrote:
  12. >>Example for a good use of goto:
  13. >>---                    ????
  14. >>------------------------------------------------------------------------------
  15. >>   HEV    hev1, hev2, hev3;     /* Event semaphores */
  16. >>   HMTX   hmtx;                 /* Mutex semaphore  */ 
  17. >>   void  *ptr;              
  18.  
  19. >>   if (!DosCreateEventSem(0, &hev1, 0, FALSE))
  20. >>       goto hev1_failed;
  21. >>
  22. >>   if (!DosCreateEventSem(0, &hev2, 0, FALSE))
  23. >>       goto hev2_failed;
  24.  
  25. >>   if (!DosCreateEventSem(0, &hev3, 0, FALSE))
  26. >>       goto hev3_failed;
  27. >>
  28. >>   if (!DosCreateMutexSem(0, &hmtx, 0, FALSE))
  29. >>       goto hmtx_failed;
  30. >>
  31. >>   if ((ptr = malloc(SOME_SIZE)) == NULL)
  32. >>       goto malloc_failed;
  33. >>
  34. >>   /* Do some stuff here */
  35. >>   return TRUE; /* We did okay */
  36. >>
  37. >>malloc_failed:
  38. >>   DosCloseMutexSem(hmtx);
  39. >>hmtx_failed:
  40. >>   DosCloseEventSem(hev3);
  41. >>hev3_failed:
  42. >>   DosCloseEventSem(hev2);
  43. >>hev2_failed:
  44. >>   DosCloseEventSem(hev1);
  45. >>hev1_failed:
  46. >>   return FALSE;
  47.  
  48.  
  49. >The above is NOT an example of a good use for the goto statement. 
  50.  
  51. Well that is what I thougut when I first saw the example, and I was about to
  52. dash off an article like you have done. But then I looked again and saw
  53. *exactly* what it was doing.
  54.  
  55. So if you believe there is a better way, please can we see it?
  56.  
  57. -- 
  58. Charles H. Lindsey -------------------------------------------------------------
  59.            At Home, doing my own thing.           Internet: chl@clw.cs.man.ac.uk
  60. Voice/Fax: +44 161 437 4506                       Janet:    chl@uk.ac.man.cs.clw
  61. Snail: 5 Clerewood Ave., CHEADLE, SK8 3JU, U.K.   UUCP:     mucs!clerew!chl
  62.